* show growth regressions with csr different covariate combinations

cd "~/Documents/econ/research/current/cognitive/estimation/dofiles"

adopath ++ "~/Documents/econ/research/stata/ado/personal/outreg"
discard

use ../data/growth_panel, clear
xtset isonum year, delta(5)

label var lgdppw "Initial log GDP per worker"
label var PRI "Institutional quality (0-100)"
label var trade_open "Trade (\% of GDP)"
label var e0 "Life expectancy (years)"
label var yr_sch "Schooling (years)"
label var csr "Child survival (per 1000)"
label var asr "Adult survival (per 1000)"
label var csr_20 "Child survival, previous generation"
label var lgdppwL25 "Log GDP per worker, lagged 25 years"

tab year if year>=1985, gen(yd) // create year dummies after 1985
drop yd1

local gmmlag 3
local xtabopts "robust twostep"
local olsopts "se varlabel squarebrack noautosumm"
local outopts "`olsopts' drop(yd*)"
local adds `""Country {\&} year effects", "yes" \ "N","'

// set e(sample) for all regressions
local lagvars "lgdppw trade_open asr PRI yr_sch"
local gmm_rhs "gmm(`lagvars', laglimits(2 `gmmlag'))"
quietly xtabond2 gPWT5 `lagvars' csr_20 yd*, `gmm_rhs' `xtabopts'
gen samp = e(sample)

// regress growth on lagged gdp instead of csr_20
local eqno = 1
local gvars "gPWT5 `lagvars' lgdppwL25 yd*"
xtabond2 `gvars' if samp, `gmm_rhs' `xtabopts'
xt_r2total
outreg, `outopts' nodisplay `reorder'		///
	ctitle("", "(`eqno')")							///
	addrow(`adds' "`e(N)'" 	///
		\ "Countries", "`:display %3.0f e(N_g)'" 	///
		\ "\(R^2 \ ({Corr(\hat{y},y)}^2)\)", 		///
			"`:display %4.2f e(r2_t)'") 

local lagvars 
foreach v in lgdppw trade_open asr PRI yr_sch {
	local eqno = `eqno' + 1
	local lagvars "`lagvars' `v'"
	local gvars "gPWT5 csr_20 `lagvars' yd*"
	local gmm_rhs "gmm(`lagvars', laglimits(2 `gmmlag'))"
	if "`ferest()'"=="" local reorder "statorder(6 7)"

di "xtabond2 `gvars' if samp, `gmm_rhs' `xtabopts'"
	xtabond2 `gvars' if samp, `gmm_rhs' `xtabopts'
	xt_r2total
	outreg, `outopts' merge	nodisplay `reorder'		///
		ctitle("", "(`eqno')")							///
		addrow(`adds' "`e(N)'" 	///
			\ "Countries", "`:display %3.0f e(N_g)'" 	///
			\ "\(R^2 \ ({Corr(\hat{y},y)}^2)\)", 		///
				"`:display %4.2f e(r2_t)'") 
}

outreg using ../../draft/images/csr_covars, replay 		///
	tex frag replace


